package com.example.sqldealtool.learnTry;

import com.google.gson.Gson;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.comparators.NullComparator;
import sun.invoke.empty.Empty;

import java.util.*;

public class LIstTry {
    public static void main(String[] args) {
        List<String> stringList = null;
        if (Objects.isNull(stringList)) {
            System.out.println("stringList is null");
            stringList = new ArrayList<>();
        }
        stringList.add("system");
        System.out.println(new Gson().toJson(stringList));
        List<String> username = Collections.emptyList();
        if (Objects.isNull(username)) {
            System.out.println("username is null");
            username = new ArrayList<>();
        }
        username.add("system");
        System.out.println(new Gson().toJson(username));
        //listTestSort();
    }
    public static void listTestSort(){

        NullComparator<Long> longNullComparator = new NullComparator<>(false);
        NullComparator<Integer> integerNullComparator = new NullComparator<>();
        List<DataCommon> list = new ArrayList<>();
        DataCommon dataCommon1 = new DataCommon(33L,4);
        DataCommon dataCommon2 = new DataCommon(22L,5);
        DataCommon dataCommon3 = new DataCommon(77L,2);
        DataCommon dataCommon4 = new DataCommon(null,2);
        list.add(dataCommon1);
        list.add(dataCommon2);
        list.add(dataCommon3);
        list.add(dataCommon4);
        System.out.println("原始顺序");
        Gson gson = new Gson();
        for(DataCommon dataCommon:list){
            System.out.println(gson.toJson(dataCommon));
        }
        list.sort(Comparator.nullsLast(Comparator.comparing(DataCommon::getKey,longNullComparator).reversed()));
        System.out.println("list.sort按key降序排序：");
        for(DataCommon dataCommon:list){
            System.out.println(gson.toJson(dataCommon));
        }
        list.sort(Comparator.nullsLast(Comparator.comparing(DataCommon::getKey,longNullComparator)));
        System.out.println("list.sort按key升序排序：");
        for(DataCommon dataCommon:list){
            System.out.println(gson.toJson(dataCommon));
        }
        list.sort(Comparator.nullsLast(Comparator.comparing(DataCommon::getValue,integerNullComparator).reversed()));
        System.out.println("list.sort按value降序排序：");
        for(DataCommon dataCommon:list){
            System.out.println(gson.toJson(dataCommon));
        }
        list.sort(Comparator.nullsLast(Comparator.comparing(DataCommon::getValue,integerNullComparator).reversed()));
        System.out.println("list.sort按value升序排序：");
        for(DataCommon dataCommon:list){
            System.out.println(gson.toJson(dataCommon));
        }
    }

}
